//
// Created by 下次一定 on 2021/9/22.
//
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

int n, m;
int v[N], w[N];
int f[N][N];
int of[N];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)cin >> v[i] >> w[i];

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            /*1.for(int k = 0; k * w[i] <= j; k++){
                f[i][j] = max(f[i][j], f[i - 1][j - w[i]*k]+v[i]*k);
            }*/
            /* 2.
              f[i][j] = f[i-1][j];
              if(j >= w[i]) f[i][j] = max(f[i][j] , f[i][j-w[i]]+v[i]);*/
        }
        for (int j = v[i]; j <= m; j++) {
            of[j] = max(of[j], of[j - w[i]] + v[i]);
        }
    }
    cout << f[n][m] << endl;
}
